from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.chrome.options import Options
from selenium.webdriver import Remote


class Base_Page():
    base_page = ""
    def __init__(self,base_page=None):
        if base_page:
            self.driver = base_page
        else:
            # self.driver = webdriver.Chrome()
            # options.add_argument("--auto-open-devtools-for-tabs")
            # self.driver = webdriver.Chrome(chrome_options=options)
            # self.driver.get('https://www.baidu.com')
            # self.driver.implicitly_wait(4)
            # -*- coding: utf-8 -*-
#seleniumgrid的配置
            # hub_url = "127.0.0.1:4444/wd/hub"
            # capabilities = DesiredCapabilities.CHROME.copy()
            # self.driver = Remote(command_executor=hub_url,desired_capabilities=capabilities)





            ChromeOptions = webdriver.ChromeOptions()
            ChromeOptions.add_argument('--headless')
            ChromeOptions.add_argument('--no-sandbox')
            ChromeOptions.add_argument('--disable-gpu')
            ChromeOptions.add_argument('--disable-dev-shm-usage')
            ChromeOptions.add_argument('window-size=1200x600')
            self.driver = webdriver.Chrome(chrome_options=ChromeOptions)
            self.driver.implicitly_wait(10)
            self.driver.get('https://www.baidu.com')
            print(self.driver.page_source)

    def finds_click(self,by,locator=None):

        if locator == None:
            return self.driver.find_element(*by).click()
        else:
            return self.driver.find_element(by,locator).click()

    def find_sendkeys(self,by,locator=None,**kwargs):

        return self.driver.find_element(*by).send_keys({kwargs})

